package com.lebang.service.buss;

import com.lebang.entity.task.TaskCommentsDetail;
import com.lebang.mapper.TaskCommentsDetailMapper;
import com.lebang.model.Whether;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author: hwq
 * @Date: 2019/8/6 17:24
 * @Version 1.0
 */
@Service
public class CommentDetailService {
    @Autowired
    private TaskCommentsDetailMapper commentsDetailMapper;

    public void insert(TaskCommentsDetail detail) {
        detail.setCreateTime(new Date());
        detail.setModifyTime(new Date());
        detail.setStatus(0);
        detail.setHasDeleted(Whether.NO.getDbIndex());
        commentsDetailMapper.insert(detail);
    }

    public TaskCommentsDetail selectById(String orderId) {
        Integer o = Integer.parseInt(orderId);
        return commentsDetailMapper.selectByPrimaryKey(o);
    }

    public Long getDetailCount(Integer commentsId) {
        return commentsDetailMapper.getDetailCount(commentsId);
    }

    public List<TaskCommentsDetail> getDetail(Integer pageSize, Integer limit, Integer commentsId) {
        return commentsDetailMapper.getDetail(pageSize,limit,commentsId);
    }

    public int updateById(Integer id, String status) {
        return commentsDetailMapper.updateById(id,status);
    }

    public boolean delDetail(String ids) {
        List<Integer> idList = new ArrayList<>();
        if (ids.contains(",")) {
            String[] temp = ids.split("[,]");
            for (String str : temp) {
                idList.add(Integer.valueOf(str));
            }
        } else {
            idList.add(Integer.valueOf(ids));
        }
        return commentsDetailMapper.deletedData(idList) > 0;
    }
}
